package com.example.login.model

import com.example.common.entity.CommendEntity
import com.example.home.entity.RecommendVideoEntity
import com.example.login.api.SimpleApiServer
import com.example.main.ui.home.entity.SimpleTypeEntity
import com.example.main.ui.home.entity.Base
import com.example.main.ui.home.entity.SimpleVideoEntity
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flow
import javax.inject.Inject

class SimpleRepository @Inject constructor(private val apiServer: SimpleApiServer){
    suspend fun typeToServer():Base<List<SimpleTypeEntity>> = apiServer.typeToServer()
    suspend fun videoToServer(id:String,page:Int,size:Int): Flow<List<SimpleVideoEntity>> {
        return flow {
            val result = apiServer.videoToServer(id,page,size)
            if(result.code == 0){
                emit(result.data)
            }else{
                emit(listOf())
            }
        }
    }
    suspend fun recommendToServer(page:Int,size:Int):Base<List<RecommendVideoEntity>> = apiServer.recommendToServer(page,size)


    suspend fun commendsToServer(dataType:Int,itemId:String):Base<List<CommendEntity>> = apiServer.commendsToServer(dataType,itemId)
}